//
// FauxjoBuilderJig
//

package net.fauxjobuilder.jig;

import java.io.*;
import java.sql.*;
import net.fauxjobuilder.*;
import net.jextra.dbconnection.*;
import net.jextra.jig.*;

@JigDef( description="Run the builder to extra schema from database." )
public class FauxjoBuilderJig implements Jig
{
    // ============================================================
    // Fields
    // ============================================================

    @JigField( "ConnDef:" )
    private String _connDef;

    @JigField( "Database Schema:" )
    private String _dbSchema;

    @JigField( "Java Package:" )
    private String _package;

    @JigField( "Java Schema Name:" )
    private String _javaSchemaName;

    @JigField( "Singleton Java Schema:" )
    private boolean _singleton;

    @JigField( "Save Directory:" )
    private String _dir;

    // ============================================================
    // Methods
    // ============================================================

    // ----------
    // public
    // ----------

    @JigCommand( "Print" )
    public void print()
        throws Exception
    {
        Connection connection = DB.getConnection( _connDef );
        FauxjoBuilder builder = new FauxjoBuilder( connection, _connDef, _dbSchema );
        PrintWriter out = new PrintWriter( System.out );
        builder.getTablesInfo();
        builder.print( out );
        out.flush();
    }

    @JigCommand( "Execute" )
    public void execute()
        throws Exception
    {
        Connection connection = DB.getConnection( _connDef );
        FauxjoBuilder builder = new FauxjoBuilder( connection, _connDef, _dbSchema );
        builder.getTablesInfo();
        builder.execute( new File( _dir ), _package, _javaSchemaName, _singleton );
    }
}

